package day_09;

import java.util.Scanner;

public class money {
    //需求：把数字金额转换成中文大写（发票）
    public static void main(String[] args) {
        //1.数字转换成中文大写
        //1.1对输入的数字进行检查
        Scanner sc=new Scanner(System.in);
        int money;
        while(true){
            System.out.println("请输入金额");
            money=sc.nextInt();
            if(money>=0&money<=9999999){
                break;
            }
            else{
                System.out.println("金额有误，请重新输入");
            }
        }
        String money2="";
        while(money!=0){
            int t=money%10;
            String ch=numbertochinese(t);
            //字符串从后往前插入
            money2=ch+money2;
            money/=10;
        }
        //2.中文大写前补零
        //2.1确定补零的个数
        int count=7-money2.length();
        //2.2补零
        for (int i = 0; i < count; i++) {
            money2="零"+money2;
        }
        //3.插入单位
        String result="";
        String[] arr={"佰","拾","万","千","佰","拾","元"};
        //遍历大写字符串
         for (int i = 0; i <money2.length() ; i++) {
             char c=money2.charAt(i);
             result=result+c+arr[i];
        }
        //4.打印结果
        System.out.println(result);

    }
    //把数字转换成大写
    public static String numbertochinese(int num){
        String[] arr={"零","壹","贰","叁","四","伍","六","七","八","九"};
        return arr[num];
    }
}
